package es.christiangarcia.android.pokepedia.model.db;

import android.database.sqlite.SQLiteDatabase;
import android.provider.BaseColumns;
import android.util.Log;

public class AttackTable implements BaseColumns {

	public static final String TABLE_NAME = "attack";

	public static final String NAME_COLUMN = "name";
	public static final String ID_TYPE_COLUMN = "id_type";
	public static final String PP_COLUMN = "pp";
	public static final String POWER_COLUMN = "power";

	//@formatter:off
	public static final String[] ALL_COLUMNS = {
			_ID,
			NAME_COLUMN,
			ID_TYPE_COLUMN,
			PP_COLUMN,
			POWER_COLUMN
	};
	public static final String DATABASE_CREATE = "CREATE TABLE " 
		+ TABLE_NAME
		+ " ("
		+ AttackTable._ID + " INTEGER PRIMARY KEY,"
		+ AttackTable.NAME_COLUMN + " TEXT UNIQUE,"
		+ AttackTable.ID_TYPE_COLUMN + " INTEGER NOT NULL,"
		+ AttackTable.PP_COLUMN + " INTEGER NOT NULL,"
		+ AttackTable.POWER_COLUMN + " INTEGER,"
		+ "FOREIGN KEY(" + AttackTable.ID_TYPE_COLUMN + ") "
		+ "REFERENCES " + TABLE_NAME + "("+ TypeTable._ID + " ON DELETE CASCADE"
		+ ");";
	// @formatter:on

	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		Log.w(AttackTable.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(database);
	}
}